﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using UCenter.BusinessContract;
using UCenter.Services;
using UCenter.Core.Web;
using UCenter.Core.Service;
using UCenter.TemplateEngine;
using UCenter.BusinessContract.Enumeration;

namespace UCenter.Controllers
{
    public class MessageController : BaseController {

        #region Short
        public ActionResult Short()
        {
            ViewData["Title"] = "短消息";
            return View();
        }
        /// <summary>
        /// get message of inbox
        /// </summary>
        /// <returns></returns>
        public string GetInBoxMessage() {
            int currentUserID = ContextService.Current.User.ID;
            var msgs = new MessageService().GetInboxMessage(currentUserID);
            return msgs.ToJSON<MessageContract>();
        }

        public void Through(int msgID, int userID, int friendID, int groupID, string note) {
            new FriendService().Through(userID, friendID,groupID,note);
            new MessageService().UpdateStatus(msgID, false);

            TemplateContract msgTemplate = new TemplateContract("ThroughFriendReqeuestMessage");
            msgTemplate.Parameters.Add("FriendUserID", ContextService.Current.User.ID.ToString());
            msgTemplate.Parameters.Add("FromUserName", ContextService.Current.User.TrueName);

            new MessageService().InsertMessage(ContextService.Current.User, userID, msgTemplate,MessageType.ThroughRequest);
        }

        public void Delete(int msgID) {
            new MessageService().DeleteMessage(msgID);
        }
        #endregion

        public ActionResult System()
        {
            ViewData["Title"] = "系统消息";
            return View();
        }

        public ActionResult Send()
        {
            ViewData["Title"] = "发送短消息";
            return View();
        }
    }
}
